﻿namespace LoanCalculatorService.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.Http;
    using LoanBusiness.Model;

    /// <summary>
    /// The loans controller.
    /// </summary>
    public class LoansController : ApiController
    {
        /// <summary>
        /// The get all loans.
        /// </summary>
        /// <returns>
        /// The <see cref="IEnumerable"/>.
        /// </returns>
        public IEnumerable<Loan> GetAllLoans()
        {
            using (var db = new LoanModelContainer())
            {
                var _loans = from loans in db.Loans select loans;
                return _loans;
            }
        }

        /// <summary>
        /// The get loan.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <returns>
        /// The <see cref="IHttpActionResult"/>.
        /// </returns>
        //public IHttpActionResult GetLoan(int id)
        //{
        //    var loan = loans.FirstOrDefault(l => l.Id == id);
        //    if (loan == null)
        //    {
        //        return NotFound();
        //    }

        //    return Ok(loan);
        //}

        //// POST api/EmployeeAPI
        //public IEnumerable<Loan> Post(Loan value)
        //{
        //    loans.Add(value);

        //    return loans;
        //}

        //// PUT api/EmployeeAPI/5
        //public void Put(int id, string value)
        //{

        //}

        //// DELETE api/EmployeeAPI/5
        //public IEnumerable<Loan> Delete(int id)
        //{
        //    loans.Remove(loans.Find(l => l.Id == id));

        //    return loans;
        //}

        /// <summary>
        /// The cal.
        /// </summary>
        /// <param name="a">
        /// The a.
        /// </param>
        /// <param name="b">
        /// The b.
        /// </param>
        /// <returns>
        /// The <see cref="double"/>.
        /// </returns>
        public double cal(
            double a,
            double b)
        {
            if (a < 0)
            {
                return 0;
            }

            return a + b;
        }
    }
}